function [inputstr, param] = parseInputs(inputs, param)
if iscell(inputs)
    sz = numel(inputs);
    param.input_size = sz;
    inputstr = cell(1, sz);
    count = 0;
    for i = 1:sz
        inputstr{i} = parseSingleInput(inputs{i}, param);
        count = count + inputstr{i}.count;
    end
    param.input_samples = count;
else
    param.input_size = 1;
    inputstr = cell(1, 1);
    inputstr{1} = parseSingleInput(inputs, param);
    param.input_samples = inputstr{1}.count;
end

end

function inputstr = parseSingleInput(input, param)
inputstr = struct('isdata', 0, 'data', [], 'count', 0, 'indir', [], ...
    'inlist', []);

if ~ischar(input) % matrix
    inputstr.data = input;
    inputstr.isdata = 1;
    inputstr.count = 1;
    
elseif exist(input, 'file') && (~exist(input, 'dir')) % file
    if param.verbose > 1
        fprintf(1, 'Treat as file: %s.\n',input);
    end
    inputstr.inlist = dir(input);
    inputstr.indir = fileparts(input);
    inputstr.count = 1;
    
elseif exist(input, 'dir') % directory
    if param.verbose > 1
        fprintf(1, 'Treat as directory: %s.\n', input);
    end
    inputstr.indir = input;
    inputstr.inlist = check_list(dir([input,'/',param.input_filetype]));
    inputstr.count = size(inputstr.inlist, 1);
    
    if param.verbose > 1
        fprintf(1, 'Found %d matches.\n', inputstr.count);
    end
    
else % pattern?
    if param.verbose > 1
        fprintf(1, 'Treat as pattern: %s.\n', input);
    end
    inputstr.indir = fileparts(input);
    inputstr.inlist = check_list(dir(input));
    inputstr.count = size(inputstr.inlist, 1);
    
    if param.verbose > 1
        fprintf(1, 'Found %d matches.\n', inputstr.count);
    end
    
end

if ~inputstr.isdata && inputstr.count == 0
    warning('features:NoMatchedItems','No matched files or directory: %s.', input);
end

end

function list = check_list(list)
    s = length(list);
    p = ones(s, 1);
    for i = 1:s
        if list(i).isdir || (list(i).bytes <= 0)
            p(i) = 0;
        end
    end
    list = list(p > 0);
end